/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.actions;

import org.eclipse.jface.action.Action;
import org.toedo.controllers.DataController;
import org.toedo.logging.Log;
import org.toedo.model.Task;
import org.toedo.model.Task.TaskStatus;

public class ChangeTaskStatusAction extends Action {
	
	private Task mTask;
	
	public ChangeTaskStatusAction(Task task) {
		mTask = task;
	}
	
	private TaskStatus getNewStatus() {
		switch (mTask.getStatus()) {
		case EnOpen : return TaskStatus.EnClosed;
		case EnClosed : return TaskStatus.EnOpen;
		default : return TaskStatus.EnClosed;
		}
	}
	
	public void run() {
		TaskStatus newStatus = getNewStatus();
		
		Log.getInstance(ChangeTaskStatusAction.class).debug(String.format("Changing %s (%s) status from %s to %s.", mTask.getTitle(), mTask.getId(), mTask.getStatus(), newStatus)); //$NON-NLS-1$
		
		DataController.getInstance().getProject().setTaskStatus(mTask, newStatus);
	}

}
